package com.base.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * 用于spring属性文件加载，同时程序中可以获取到属性文件中的定义属性
 * @author bill.yangjb
 *
 */
public class ReadPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
    private static Map<String, Object> propertiesMap;

    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {  
        super.processProperties(beanFactoryToProcess, props);
        propertiesMap = new HashMap<String, Object>();
        for (Object key : props.keySet()) {
            String keyStr = key.toString();
            String value = props.getProperty(keyStr);
            //System.out.println("key:"+key+"   value:"+value);
            propertiesMap.put(keyStr, value);
        }
        //System.out.println();
    }
    public static Object getContextProperty(String name) {
         String value = (String)propertiesMap.get(name);
         return value;
    }
    
}
